package io.itit.ecp.admin.server.service.impl;

import icu.mhb.mybatisplus.plugln.base.service.impl.JoinServiceImpl;
import io.itit.ecp.admin.server.entity.UserDataRangeEntity;
import io.itit.ecp.admin.server.mapper.UserDataRangeMapper;
import io.itit.ecp.admin.server.service.IUserDataRangeService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *
 * @Author：Roy
 * @Description：用户数据范围服务实现类
 * @Date：Create by 2024-01-09 11:37:16
 */
@Service
public class UserDataRangeServiceImpl extends JoinServiceImpl<UserDataRangeMapper, UserDataRangeEntity> implements IUserDataRangeService {

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Boolean save(String userId, String dataRangeId) {
        lambdaUpdate().eq(UserDataRangeEntity::getUserId, userId).remove();
        UserDataRangeEntity entity = new UserDataRangeEntity();
        entity.setUserId(userId);
        entity.setDataRangeId(dataRangeId);
        return save(entity);
    }
}